/**
 * 
 */
package codingformat.wizards;

import java.util.Arrays;
import java.util.List;

import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.AbstractElementListSelectionDialog;


/**
 * @author Administrator
 * 选择工程内的包，并进行新建包
 */
public class PackageSelectionAndCreateDialog extends AbstractElementListSelectionDialog{

	private Object[] fElements;
	private String projectName;
	private List<IPackageFragmentRoot> listRoot;
	private String selectSourceFolder;
	private String selectPackage;

	/**
     * Creates a list selection dialog.
     * @param parent   the parent widget.
     * @param renderer the label renderer.
     */
    public PackageSelectionAndCreateDialog(Shell parent, ILabelProvider renderer) {
        super(parent, renderer);
    }
    
    public PackageSelectionAndCreateDialog(Shell parent, ILabelProvider renderer ,String projectName) {
        super(parent, renderer);
        this.projectName = projectName;
    }

    /**
     * Sets the elements of the list.
     * @param elements the elements of the list.
     */
    public void setElements(Object[] elements) {
        fElements = elements;
    }

    /*
     * @see SelectionStatusDialog#computeResult()
     */
    protected void computeResult() {
        setResult(Arrays.asList(getSelectedElements()));
    }

    /*
     * @see Dialog#createDialogArea(Composite)
     */
    protected Control createDialogArea(Composite parent) {
        Composite contents = (Composite) super.createDialogArea(parent);
        GridData data = new GridData();
        data.grabExcessVerticalSpace = false;
        data.grabExcessHorizontalSpace = true;
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
       // sourceFolderCombo.setLayoutData(data);
        createMessageArea(contents);
        createFilterText(contents);
        createFilteredList(contents);
        setListElements(fElements);
        setSelection(getInitialElementSelections().toArray());
        return contents;
    }
    public void setListRoot(List<IPackageFragmentRoot> listRoot) {
		this.listRoot = listRoot;
	}
    
    public String getSelectSourceFolder() {
		return selectSourceFolder;
	}

	public void setSelectSourceFolder(String selectSourceFolder) {
		this.selectSourceFolder = selectSourceFolder;
	}
	
	public String getSelectPackage() {
		return selectPackage;
	}

	public void setSelectPackage(String selectPackage) {
		this.selectPackage = selectPackage;
	}
}
